{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1、先导入为们需要的模块\n",
    "import requests\n",
    "\n",
    "\n",
    "api_secret = \"IyaoDLVczwZU3CiKpu2IGj-7ZJYJ_U6n\"\n",
    "# 2、输入我们API_Key\n",
    "api_key = 'Uhqerp2LAPh_ijl6RdApSidmTnH50_wS'  # Replace with a valid Subscription Key here.\n",
    "\n",
    "\n",
    "# 3、目标url\n",
    "# 这里也可以使用本地图片 例如：filepath =\"image/tupian.jpg\"\n",
    "BASE_URL = 'https://api-cn.faceplusplus.com/facepp/v3/detect' \n",
    "img_url = 'http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg'\n",
    "\n",
    "# 4、沿用API文档的示范代码,准备我们的headers和图片(数据)\n",
    "\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "}\n",
    "\n",
    "# 5、准备symbol ? 后面的数据\n",
    "\n",
    "payload = {\n",
    "    \"image_url\":img_url,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,smiling,emotion,headpose,facequality,blur,eyestatus,ethnicity,beauty,mouthstatus,eyegaze,skinstatus', \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  6、requests发送我们请求\n",
    "r = requests.post(BASE_URL, params=payload, headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1602815809,3e934caa-3d1c-4d80-890d-fa84f28fb2b9\",\"time_used\":1447,\"faces\":[{\"face_token\":\"8a6fb634a214e2f309dcb73fde321b9e\",\"face_rectangle\":{\"top\":123,\"left\":138,\"width\":90,\"height\":90},\"attributes\":{\"gender\":{\"value\":\"Male\"},\"age\":{\"value\":23},\"smile\":{\"value\":99.995,\"threshold\":50.000},\"headpose\":{\"pitch_angle\":0.6047415,\"roll_angle\":-2.497425,\"yaw_angle\":-7.126226},\"blur\":{\"blurness\":{\"value\":0.370,\"threshold\":50.000},\"motionblur\":{\"value\":0.370,\"threshold\":50.000},\"gaussianblur\":{\"value\":0.370,\"threshold\":50.000}},\"eyestatus\":{\"left_eye_status\":{\"no_glass_eye_open\":99.964,\"no_glass_eye_close\":0.000,\"normal_glass_eye_open\":0.034,\"normal_glass_eye_close\":0.000,\"dark_glasses\":0.000,\"occlusion\":0.002},\"right_eye_status\":{\"no_glass_eye_open\":94.241,\"no_glass_eye_close\":0.003,\"normal_glass_eye_open\":5.645,\"normal_glass_eye_close\":0.053,\"dark_glasses\":0.001,\"occlusion\":0.057}},\"emotion\":{\"anger\":0.059,\"disgust\":0.059,\"fear\":0.059,\"happiness\":42.294,\"neutral\":52.431,\"sadness\":4.920,\"surprise\":0.179},\"facequality\":{\"value\":88.584,\"threshold\":70.100},\"ethnicity\":{\"value\":\"\"},\"beauty\":{\"male_score\":63.735,\"female_score\":62.853},\"mouthstatus\":{\"surgical_mask_or_respirator\":0.000,\"other_occlusion\":0.000,\"close\":100.000,\"open\":0.000},\"eyegaze\":{\"left_eye_gaze\":{\"position_x_coordinate\":0.471,\"position_y_coordinate\":0.465,\"vector_x_component\":-0.027,\"vector_y_component\":0.190,\"vector_z_component\":0.981},\"right_eye_gaze\":{\"position_x_coordinate\":0.457,\"position_y_coordinate\":0.461,\"vector_x_component\":-0.214,\"vector_y_component\":0.277,\"vector_z_component\":0.937}},\"skinstatus\":{\"health\":70.297,\"stain\":1.686,\"dark_circle\":2.601,\"acne\":0.272},\"glass\":{\"value\":\"None\"}}},{\"face_token\":\"1acf34b8b5cf290c9321a73fb01c13a3\",\"face_rectangle\":{\"top\":122,\"left\":373,\"width\":65,\"height\":65},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":37},\"smile\":{\"value\":98.866,\"threshold\":50.000},\"headpose\":{\"pitch_angle\":3.2396555,\"roll_angle\":-3.6525803,\"yaw_angle\":-4.9724226},\"blur\":{\"blurness\":{\"value\":1.032,\"threshold\":50.000},\"motionblur\":{\"value\":1.032,\"threshold\":50.000},\"gaussianblur\":{\"value\":1.032,\"threshold\":50.000}},\"eyestatus\":{\"left_eye_status\":{\"no_glass_eye_open\":99.462,\"no_glass_eye_close\":0.000,\"normal_glass_eye_open\":0.538,\"normal_glass_eye_close\":0.000,\"dark_glasses\":0.000,\"occlusion\":0.000},\"right_eye_status\":{\"no_glass_eye_open\":99.308,\"no_glass_eye_close\":0.000,\"normal_glass_eye_open\":0.689,\"normal_glass_eye_close\":0.002,\"dark_glasses\":0.000,\"occlusion\":0.001}},\"emotion\":{\"anger\":0.169,\"disgust\":7.280,\"fear\":0.138,\"happiness\":17.689,\"neutral\":8.067,\"sadness\":66.519,\"surprise\":0.138},\"facequality\":{\"value\":90.515,\"threshold\":70.100},\"ethnicity\":{\"value\":\"\"},\"beauty\":{\"male_score\":47.132,\"female_score\":49.756},\"mouthstatus\":{\"surgical_mask_or_respirator\":0.000,\"other_occlusion\":0.003,\"close\":93.274,\"open\":6.723},\"eyegaze\":{\"left_eye_gaze\":{\"position_x_coordinate\":0.483,\"position_y_coordinate\":0.432,\"vector_x_component\":-0.017,\"vector_y_component\":0.028,\"vector_z_component\":0.999},\"right_eye_gaze\":{\"position_x_coordinate\":0.461,\"position_y_coordinate\":0.437,\"vector_x_component\":-0.224,\"vector_y_component\":0.158,\"vector_z_component\":0.962}},\"skinstatus\":{\"health\":78.151,\"stain\":7.777,\"dark_circle\":4.751,\"acne\":6.603},\"glass\":{\"value\":\"None\"}}},{\"face_token\":\"9a38db8b08f8677d792c2844a1d7a8d4\",\"face_rectangle\":{\"top\":46,\"left\":675,\"width\":54,\"height\":54},\"attributes\":{\"gender\":{\"value\":\"Male\"},\"age\":{\"value\":23},\"smile\":{\"value\":100.000,\"threshold\":50.000},\"headpose\":{\"pitch_angle\":5.4655566,\"roll_angle\":-1.2741443,\"yaw_angle\":0.04951204},\"blur\":{\"blurness\":{\"value\":4.988,\"threshold\":50.000},\"motionblur\":{\"value\":4.988,\"threshold\":50.000},\"gaussianblur\":{\"value\":4.988,\"threshold\":50.000}},\"eyestatus\":{\"left_eye_status\":{\"no_glass_eye_open\":0.296,\"no_glass_eye_close\":0.026,\"normal_glass_eye_open\":99.656,\"normal_glass_eye_close\":0.016,\"dark_glasses\":0.003,\"occlusion\":0.004},\"right_eye_status\":{\"no_glass_eye_open\":0.026,\"no_glass_eye_close\":0.000,\"normal_glass_eye_open\":99.969,\"normal_glass_eye_close\":0.004,\"dark_glasses\":0.000,\"occlusion\":0.000}},\"emotion\":{\"anger\":0.000,\"disgust\":0.000,\"fear\":0.000,\"happiness\":99.996,\"neutral\":0.001,\"sadness\":0.002,\"surprise\":0.001},\"facequality\":{\"value\":92.534,\"threshold\":70.100},\"ethnicity\":{\"value\":\"\"},\"beauty\":{\"male_score\":41.427,\"female_score\":42.018},\"mouthstatus\":{\"surgical_mask_or_respirator\":0.000,\"other_occlusion\":0.000,\"close\":0.000,\"open\":100.000},\"eyegaze\":{\"left_eye_gaze\":{\"position_x_coordinate\":0.470,\"position_y_coordinate\":0.415,\"vector_x_component\":0.785,\"vector_y_component\":0.108,\"vector_z_component\":0.610},\"right_eye_gaze\":{\"position_x_coordinate\":0.544,\"position_y_coordinate\":0.081,\"vector_x_component\":-0.618,\"vector_y_component\":-0.531,\"vector_z_component\":0.579}},\"skinstatus\":{\"health\":0.500,\"stain\":8.234,\"dark_circle\":3.244,\"acne\":0.142},\"glass\":{\"value\":\"Normal\"}}},{\"face_token\":\"4f5d95b66ce2538efa8168b59423cc44\",\"face_rectangle\":{\"top\":98,\"left\":235,\"width\":53,\"height\":53},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":22},\"smile\":{\"value\":99.997,\"threshold\":50.000},\"headpose\":{\"pitch_angle\":-2.531932,\"roll_angle\":4.016266,\"yaw_angle\":-2.450839},\"blur\":{\"blurness\":{\"value\":42.713,\"threshold\":50.000},\"motionblur\":{\"value\":42.713,\"threshold\":50.000},\"gaussianblur\":{\"value\":42.713,\"threshold\":50.000}},\"eyestatus\":{\"left_eye_status\":{\"no_glass_eye_open\":0.533,\"no_glass_eye_close\":0.019,\"normal_glass_eye_open\":98.923,\"normal_glass_eye_close\":0.495,\"dark_glasses\":0.005,\"occlusion\":0.026},\"right_eye_status\":{\"no_glass_eye_open\":7.160,\"no_glass_eye_close\":0.337,\"normal_glass_eye_open\":92.389,\"normal_glass_eye_close\":0.098,\"dark_glasses\":0.001,\"occlusion\":0.015}},\"emotion\":{\"anger\":0.000,\"disgust\":0.001,\"fear\":0.000,\"happiness\":99.990,\"neutral\":0.009,\"sadness\":0.000,\"surprise\":0.000},\"facequality\":{\"value\":31.997,\"threshold\":70.100},\"ethnicity\":{\"value\":\"\"},\"beauty\":{\"male_score\":38.410,\"female_score\":39.542},\"mouthstatus\":{\"surgical_mask_or_respirator\":0.000,\"other_occlusion\":0.011,\"close\":0.009,\"open\":99.980},\"eyegaze\":{\"left_eye_gaze\":{\"position_x_coordinate\":0.553,\"position_y_coordinate\":0.489,\"vector_x_component\":0.454,\"vector_y_component\":0.405,\"vector_z_component\":0.794},\"right_eye_gaze\":{\"position_x_coordinate\":0.302,\"position_y_coordinate\":0.495,\"vector_x_component\":-0.820,\"vector_y_component\":0.374,\"vector_z_component\":0.432}},\"skinstatus\":{\"health\":3.319,\"stain\":6.990,\"dark_circle\":5.649,\"acne\":0.655},\"glass\":{\"value\":\"Normal\"}}},{\"face_token\":\"114c8d0305c8a03d9bd7d29a607601f0\",\"face_rectangle\":{\"top\":75,\"left\":444,\"width\":52,\"height\":52},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":28},\"smile\":{\"value\":99.999,\"threshold\":50.000},\"headpose\":{\"pitch_angle\":3.8443422,\"roll_angle\":0.79213506,\"yaw_angle\":-1.5878781},\"blur\":{\"blurness\":{\"value\":93.521,\"threshold\":50.000},\"motionblur\":{\"value\":93.521,\"threshold\":50.000},\"gaussianblur\":{\"value\":93.521,\"threshold\":50.000}},\"eyestatus\":{\"left_eye_status\":{\"no_glass_eye_open\":99.548,\"no_glass_eye_close\":0.000,\"normal_glass_eye_open\":0.449,\"normal_glass_eye_close\":0.002,\"dark_glasses\":0.000,\"occlusion\":0.001},\"right_eye_status\":{\"no_glass_eye_open\":98.901,\"no_glass_eye_close\":0.000,\"normal_glass_eye_open\":1.095,\"normal_glass_eye_close\":0.001,\"dark_glasses\":0.000,\"occlusion\":0.002}},\"emotion\":{\"anger\":0.001,\"disgust\":0.001,\"fear\":0.027,\"happiness\":99.933,\"neutral\":0.027,\"sadness\":0.010,\"surprise\":0.001},\"facequality\":{\"value\":0.006,\"threshold\":70.100},\"ethnicity\":{\"value\":\"\"},\"beauty\":{\"male_score\":48.260,\"female_score\":46.071},\"mouthstatus\":{\"surgical_mask_or_respirator\":0.000,\"other_occlusion\":0.003,\"close\":0.011,\"open\":99.985},\"eyegaze\":{\"left_eye_gaze\":{\"position_x_coordinate\":0.500,\"position_y_coordinate\":0.421,\"vector_x_component\":0.487,\"vector_y_component\":0.161,\"vector_z_component\":0.859},\"right_eye_gaze\":{\"position_x_coordinate\":0.487,\"position_y_coordinate\":0.402,\"vector_x_component\":-0.271,\"vector_y_component\":0.207,\"vector_z_component\":0.940}},\"skinstatus\":{\"health\":82.386,\"stain\":1.748,\"dark_circle\":3.866,\"acne\":0.430},\"glass\":{\"value\":\"None\"}}},{\"face_token\":\"04c3511fc75d3bd60fd73f67889a33e5\",\"face_rectangle\":{\"top\":98,\"left\":537,\"width\":48,\"height\":48}}],\"image_id\":\"TfC1AByqtXhfuQ6DruqVww==\",\"face_num\":6}\\n'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1602815809,3e934caa-3d1c-4d80-890d-fa84f28fb2b9',\n",
       " 'time_used': 1447,\n",
       " 'faces': [{'face_token': '8a6fb634a214e2f309dcb73fde321b9e',\n",
       "   'face_rectangle': {'top': 123, 'left': 138, 'width': 90, 'height': 90},\n",
       "   'attributes': {'gender': {'value': 'Male'},\n",
       "    'age': {'value': 23},\n",
       "    'smile': {'value': 99.995, 'threshold': 50.0},\n",
       "    'headpose': {'pitch_angle': 0.6047415,\n",
       "     'roll_angle': -2.497425,\n",
       "     'yaw_angle': -7.126226},\n",
       "    'blur': {'blurness': {'value': 0.37, 'threshold': 50.0},\n",
       "     'motionblur': {'value': 0.37, 'threshold': 50.0},\n",
       "     'gaussianblur': {'value': 0.37, 'threshold': 50.0}},\n",
       "    'eyestatus': {'left_eye_status': {'no_glass_eye_open': 99.964,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'normal_glass_eye_open': 0.034,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0,\n",
       "      'occlusion': 0.002},\n",
       "     'right_eye_status': {'no_glass_eye_open': 94.241,\n",
       "      'no_glass_eye_close': 0.003,\n",
       "      'normal_glass_eye_open': 5.645,\n",
       "      'normal_glass_eye_close': 0.053,\n",
       "      'dark_glasses': 0.001,\n",
       "      'occlusion': 0.057}},\n",
       "    'emotion': {'anger': 0.059,\n",
       "     'disgust': 0.059,\n",
       "     'fear': 0.059,\n",
       "     'happiness': 42.294,\n",
       "     'neutral': 52.431,\n",
       "     'sadness': 4.92,\n",
       "     'surprise': 0.179},\n",
       "    'facequality': {'value': 88.584, 'threshold': 70.1},\n",
       "    'ethnicity': {'value': ''},\n",
       "    'beauty': {'male_score': 63.735, 'female_score': 62.853},\n",
       "    'mouthstatus': {'surgical_mask_or_respirator': 0.0,\n",
       "     'other_occlusion': 0.0,\n",
       "     'close': 100.0,\n",
       "     'open': 0.0},\n",
       "    'eyegaze': {'left_eye_gaze': {'position_x_coordinate': 0.471,\n",
       "      'position_y_coordinate': 0.465,\n",
       "      'vector_x_component': -0.027,\n",
       "      'vector_y_component': 0.19,\n",
       "      'vector_z_component': 0.981},\n",
       "     'right_eye_gaze': {'position_x_coordinate': 0.457,\n",
       "      'position_y_coordinate': 0.461,\n",
       "      'vector_x_component': -0.214,\n",
       "      'vector_y_component': 0.277,\n",
       "      'vector_z_component': 0.937}},\n",
       "    'skinstatus': {'health': 70.297,\n",
       "     'stain': 1.686,\n",
       "     'dark_circle': 2.601,\n",
       "     'acne': 0.272},\n",
       "    'glass': {'value': 'None'}}},\n",
       "  {'face_token': '1acf34b8b5cf290c9321a73fb01c13a3',\n",
       "   'face_rectangle': {'top': 122, 'left': 373, 'width': 65, 'height': 65},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 37},\n",
       "    'smile': {'value': 98.866, 'threshold': 50.0},\n",
       "    'headpose': {'pitch_angle': 3.2396555,\n",
       "     'roll_angle': -3.6525803,\n",
       "     'yaw_angle': -4.9724226},\n",
       "    'blur': {'blurness': {'value': 1.032, 'threshold': 50.0},\n",
       "     'motionblur': {'value': 1.032, 'threshold': 50.0},\n",
       "     'gaussianblur': {'value': 1.032, 'threshold': 50.0}},\n",
       "    'eyestatus': {'left_eye_status': {'no_glass_eye_open': 99.462,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'normal_glass_eye_open': 0.538,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0,\n",
       "      'occlusion': 0.0},\n",
       "     'right_eye_status': {'no_glass_eye_open': 99.308,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'normal_glass_eye_open': 0.689,\n",
       "      'normal_glass_eye_close': 0.002,\n",
       "      'dark_glasses': 0.0,\n",
       "      'occlusion': 0.001}},\n",
       "    'emotion': {'anger': 0.169,\n",
       "     'disgust': 7.28,\n",
       "     'fear': 0.138,\n",
       "     'happiness': 17.689,\n",
       "     'neutral': 8.067,\n",
       "     'sadness': 66.519,\n",
       "     'surprise': 0.138},\n",
       "    'facequality': {'value': 90.515, 'threshold': 70.1},\n",
       "    'ethnicity': {'value': ''},\n",
       "    'beauty': {'male_score': 47.132, 'female_score': 49.756},\n",
       "    'mouthstatus': {'surgical_mask_or_respirator': 0.0,\n",
       "     'other_occlusion': 0.003,\n",
       "     'close': 93.274,\n",
       "     'open': 6.723},\n",
       "    'eyegaze': {'left_eye_gaze': {'position_x_coordinate': 0.483,\n",
       "      'position_y_coordinate': 0.432,\n",
       "      'vector_x_component': -0.017,\n",
       "      'vector_y_component': 0.028,\n",
       "      'vector_z_component': 0.999},\n",
       "     'right_eye_gaze': {'position_x_coordinate': 0.461,\n",
       "      'position_y_coordinate': 0.437,\n",
       "      'vector_x_component': -0.224,\n",
       "      'vector_y_component': 0.158,\n",
       "      'vector_z_component': 0.962}},\n",
       "    'skinstatus': {'health': 78.151,\n",
       "     'stain': 7.777,\n",
       "     'dark_circle': 4.751,\n",
       "     'acne': 6.603},\n",
       "    'glass': {'value': 'None'}}},\n",
       "  {'face_token': '9a38db8b08f8677d792c2844a1d7a8d4',\n",
       "   'face_rectangle': {'top': 46, 'left': 675, 'width': 54, 'height': 54},\n",
       "   'attributes': {'gender': {'value': 'Male'},\n",
       "    'age': {'value': 23},\n",
       "    'smile': {'value': 100.0, 'threshold': 50.0},\n",
       "    'headpose': {'pitch_angle': 5.4655566,\n",
       "     'roll_angle': -1.2741443,\n",
       "     'yaw_angle': 0.04951204},\n",
       "    'blur': {'blurness': {'value': 4.988, 'threshold': 50.0},\n",
       "     'motionblur': {'value': 4.988, 'threshold': 50.0},\n",
       "     'gaussianblur': {'value': 4.988, 'threshold': 50.0}},\n",
       "    'eyestatus': {'left_eye_status': {'no_glass_eye_open': 0.296,\n",
       "      'no_glass_eye_close': 0.026,\n",
       "      'normal_glass_eye_open': 99.656,\n",
       "      'normal_glass_eye_close': 0.016,\n",
       "      'dark_glasses': 0.003,\n",
       "      'occlusion': 0.004},\n",
       "     'right_eye_status': {'no_glass_eye_open': 0.026,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'normal_glass_eye_open': 99.969,\n",
       "      'normal_glass_eye_close': 0.004,\n",
       "      'dark_glasses': 0.0,\n",
       "      'occlusion': 0.0}},\n",
       "    'emotion': {'anger': 0.0,\n",
       "     'disgust': 0.0,\n",
       "     'fear': 0.0,\n",
       "     'happiness': 99.996,\n",
       "     'neutral': 0.001,\n",
       "     'sadness': 0.002,\n",
       "     'surprise': 0.001},\n",
       "    'facequality': {'value': 92.534, 'threshold': 70.1},\n",
       "    'ethnicity': {'value': ''},\n",
       "    'beauty': {'male_score': 41.427, 'female_score': 42.018},\n",
       "    'mouthstatus': {'surgical_mask_or_respirator': 0.0,\n",
       "     'other_occlusion': 0.0,\n",
       "     'close': 0.0,\n",
       "     'open': 100.0},\n",
       "    'eyegaze': {'left_eye_gaze': {'position_x_coordinate': 0.47,\n",
       "      'position_y_coordinate': 0.415,\n",
       "      'vector_x_component': 0.785,\n",
       "      'vector_y_component': 0.108,\n",
       "      'vector_z_component': 0.61},\n",
       "     'right_eye_gaze': {'position_x_coordinate': 0.544,\n",
       "      'position_y_coordinate': 0.081,\n",
       "      'vector_x_component': -0.618,\n",
       "      'vector_y_component': -0.531,\n",
       "      'vector_z_component': 0.579}},\n",
       "    'skinstatus': {'health': 0.5,\n",
       "     'stain': 8.234,\n",
       "     'dark_circle': 3.244,\n",
       "     'acne': 0.142},\n",
       "    'glass': {'value': 'Normal'}}},\n",
       "  {'face_token': '4f5d95b66ce2538efa8168b59423cc44',\n",
       "   'face_rectangle': {'top': 98, 'left': 235, 'width': 53, 'height': 53},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 22},\n",
       "    'smile': {'value': 99.997, 'threshold': 50.0},\n",
       "    'headpose': {'pitch_angle': -2.531932,\n",
       "     'roll_angle': 4.016266,\n",
       "     'yaw_angle': -2.450839},\n",
       "    'blur': {'blurness': {'value': 42.713, 'threshold': 50.0},\n",
       "     'motionblur': {'value': 42.713, 'threshold': 50.0},\n",
       "     'gaussianblur': {'value': 42.713, 'threshold': 50.0}},\n",
       "    'eyestatus': {'left_eye_status': {'no_glass_eye_open': 0.533,\n",
       "      'no_glass_eye_close': 0.019,\n",
       "      'normal_glass_eye_open': 98.923,\n",
       "      'normal_glass_eye_close': 0.495,\n",
       "      'dark_glasses': 0.005,\n",
       "      'occlusion': 0.026},\n",
       "     'right_eye_status': {'no_glass_eye_open': 7.16,\n",
       "      'no_glass_eye_close': 0.337,\n",
       "      'normal_glass_eye_open': 92.389,\n",
       "      'normal_glass_eye_close': 0.098,\n",
       "      'dark_glasses': 0.001,\n",
       "      'occlusion': 0.015}},\n",
       "    'emotion': {'anger': 0.0,\n",
       "     'disgust': 0.001,\n",
       "     'fear': 0.0,\n",
       "     'happiness': 99.99,\n",
       "     'neutral': 0.009,\n",
       "     'sadness': 0.0,\n",
       "     'surprise': 0.0},\n",
       "    'facequality': {'value': 31.997, 'threshold': 70.1},\n",
       "    'ethnicity': {'value': ''},\n",
       "    'beauty': {'male_score': 38.41, 'female_score': 39.542},\n",
       "    'mouthstatus': {'surgical_mask_or_respirator': 0.0,\n",
       "     'other_occlusion': 0.011,\n",
       "     'close': 0.009,\n",
       "     'open': 99.98},\n",
       "    'eyegaze': {'left_eye_gaze': {'position_x_coordinate': 0.553,\n",
       "      'position_y_coordinate': 0.489,\n",
       "      'vector_x_component': 0.454,\n",
       "      'vector_y_component': 0.405,\n",
       "      'vector_z_component': 0.794},\n",
       "     'right_eye_gaze': {'position_x_coordinate': 0.302,\n",
       "      'position_y_coordinate': 0.495,\n",
       "      'vector_x_component': -0.82,\n",
       "      'vector_y_component': 0.374,\n",
       "      'vector_z_component': 0.432}},\n",
       "    'skinstatus': {'health': 3.319,\n",
       "     'stain': 6.99,\n",
       "     'dark_circle': 5.649,\n",
       "     'acne': 0.655},\n",
       "    'glass': {'value': 'Normal'}}},\n",
       "  {'face_token': '114c8d0305c8a03d9bd7d29a607601f0',\n",
       "   'face_rectangle': {'top': 75, 'left': 444, 'width': 52, 'height': 52},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 28},\n",
       "    'smile': {'value': 99.999, 'threshold': 50.0},\n",
       "    'headpose': {'pitch_angle': 3.8443422,\n",
       "     'roll_angle': 0.79213506,\n",
       "     'yaw_angle': -1.5878781},\n",
       "    'blur': {'blurness': {'value': 93.521, 'threshold': 50.0},\n",
       "     'motionblur': {'value': 93.521, 'threshold': 50.0},\n",
       "     'gaussianblur': {'value': 93.521, 'threshold': 50.0}},\n",
       "    'eyestatus': {'left_eye_status': {'no_glass_eye_open': 99.548,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'normal_glass_eye_open': 0.449,\n",
       "      'normal_glass_eye_close': 0.002,\n",
       "      'dark_glasses': 0.0,\n",
       "      'occlusion': 0.001},\n",
       "     'right_eye_status': {'no_glass_eye_open': 98.901,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'normal_glass_eye_open': 1.095,\n",
       "      'normal_glass_eye_close': 0.001,\n",
       "      'dark_glasses': 0.0,\n",
       "      'occlusion': 0.002}},\n",
       "    'emotion': {'anger': 0.001,\n",
       "     'disgust': 0.001,\n",
       "     'fear': 0.027,\n",
       "     'happiness': 99.933,\n",
       "     'neutral': 0.027,\n",
       "     'sadness': 0.01,\n",
       "     'surprise': 0.001},\n",
       "    'facequality': {'value': 0.006, 'threshold': 70.1},\n",
       "    'ethnicity': {'value': ''},\n",
       "    'beauty': {'male_score': 48.26, 'female_score': 46.071},\n",
       "    'mouthstatus': {'surgical_mask_or_respirator': 0.0,\n",
       "     'other_occlusion': 0.003,\n",
       "     'close': 0.011,\n",
       "     'open': 99.985},\n",
       "    'eyegaze': {'left_eye_gaze': {'position_x_coordinate': 0.5,\n",
       "      'position_y_coordinate': 0.421,\n",
       "      'vector_x_component': 0.487,\n",
       "      'vector_y_component': 0.161,\n",
       "      'vector_z_component': 0.859},\n",
       "     'right_eye_gaze': {'position_x_coordinate': 0.487,\n",
       "      'position_y_coordinate': 0.402,\n",
       "      'vector_x_component': -0.271,\n",
       "      'vector_y_component': 0.207,\n",
       "      'vector_z_component': 0.94}},\n",
       "    'skinstatus': {'health': 82.386,\n",
       "     'stain': 1.748,\n",
       "     'dark_circle': 3.866,\n",
       "     'acne': 0.43},\n",
       "    'glass': {'value': 'None'}}},\n",
       "  {'face_token': '04c3511fc75d3bd60fd73f67889a33e5',\n",
       "   'face_rectangle': {'top': 98, 'left': 537, 'width': 48, 'height': 48}}],\n",
       " 'image_id': 'TfC1AByqtXhfuQ6DruqVww==',\n",
       " 'face_num': 6}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# requests 巧妙的方法   r = response\n",
    "results = r.json() # \n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "# from pandas.io.json import json_normalize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.json_normalize(results,record_path='faces')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <th>face_rectangle.height</th>\n",
       "      <th>attributes.gender.value</th>\n",
       "      <th>attributes.age.value</th>\n",
       "      <th>attributes.smile.value</th>\n",
       "      <th>attributes.smile.threshold</th>\n",
       "      <th>attributes.headpose.pitch_angle</th>\n",
       "      <th>...</th>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.position_x_coordinate</th>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.position_y_coordinate</th>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_x_component</th>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_y_component</th>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_z_component</th>\n",
       "      <th>attributes.skinstatus.health</th>\n",
       "      <th>attributes.skinstatus.stain</th>\n",
       "      <th>attributes.skinstatus.dark_circle</th>\n",
       "      <th>attributes.skinstatus.acne</th>\n",
       "      <th>attributes.glass.value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8a6fb634a214e2f309dcb73fde321b9e</td>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "      <td>Male</td>\n",
       "      <td>23.0</td>\n",
       "      <td>99.995</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.604742</td>\n",
       "      <td>...</td>\n",
       "      <td>0.457</td>\n",
       "      <td>0.461</td>\n",
       "      <td>-0.214</td>\n",
       "      <td>0.277</td>\n",
       "      <td>0.937</td>\n",
       "      <td>70.297</td>\n",
       "      <td>1.686</td>\n",
       "      <td>2.601</td>\n",
       "      <td>0.272</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1acf34b8b5cf290c9321a73fb01c13a3</td>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "      <td>Female</td>\n",
       "      <td>37.0</td>\n",
       "      <td>98.866</td>\n",
       "      <td>50.0</td>\n",
       "      <td>3.239656</td>\n",
       "      <td>...</td>\n",
       "      <td>0.461</td>\n",
       "      <td>0.437</td>\n",
       "      <td>-0.224</td>\n",
       "      <td>0.158</td>\n",
       "      <td>0.962</td>\n",
       "      <td>78.151</td>\n",
       "      <td>7.777</td>\n",
       "      <td>4.751</td>\n",
       "      <td>6.603</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9a38db8b08f8677d792c2844a1d7a8d4</td>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "      <td>Male</td>\n",
       "      <td>23.0</td>\n",
       "      <td>100.000</td>\n",
       "      <td>50.0</td>\n",
       "      <td>5.465557</td>\n",
       "      <td>...</td>\n",
       "      <td>0.544</td>\n",
       "      <td>0.081</td>\n",
       "      <td>-0.618</td>\n",
       "      <td>-0.531</td>\n",
       "      <td>0.579</td>\n",
       "      <td>0.500</td>\n",
       "      <td>8.234</td>\n",
       "      <td>3.244</td>\n",
       "      <td>0.142</td>\n",
       "      <td>Normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4f5d95b66ce2538efa8168b59423cc44</td>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "      <td>Female</td>\n",
       "      <td>22.0</td>\n",
       "      <td>99.997</td>\n",
       "      <td>50.0</td>\n",
       "      <td>-2.531932</td>\n",
       "      <td>...</td>\n",
       "      <td>0.302</td>\n",
       "      <td>0.495</td>\n",
       "      <td>-0.820</td>\n",
       "      <td>0.374</td>\n",
       "      <td>0.432</td>\n",
       "      <td>3.319</td>\n",
       "      <td>6.990</td>\n",
       "      <td>5.649</td>\n",
       "      <td>0.655</td>\n",
       "      <td>Normal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>114c8d0305c8a03d9bd7d29a607601f0</td>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "      <td>Female</td>\n",
       "      <td>28.0</td>\n",
       "      <td>99.999</td>\n",
       "      <td>50.0</td>\n",
       "      <td>3.844342</td>\n",
       "      <td>...</td>\n",
       "      <td>0.487</td>\n",
       "      <td>0.402</td>\n",
       "      <td>-0.271</td>\n",
       "      <td>0.207</td>\n",
       "      <td>0.940</td>\n",
       "      <td>82.386</td>\n",
       "      <td>1.748</td>\n",
       "      <td>3.866</td>\n",
       "      <td>0.430</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>04c3511fc75d3bd60fd73f67889a33e5</td>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6 rows × 61 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  face_rectangle.top  face_rectangle.left  \\\n",
       "0  8a6fb634a214e2f309dcb73fde321b9e                 123                  138   \n",
       "1  1acf34b8b5cf290c9321a73fb01c13a3                 122                  373   \n",
       "2  9a38db8b08f8677d792c2844a1d7a8d4                  46                  675   \n",
       "3  4f5d95b66ce2538efa8168b59423cc44                  98                  235   \n",
       "4  114c8d0305c8a03d9bd7d29a607601f0                  75                  444   \n",
       "5  04c3511fc75d3bd60fd73f67889a33e5                  98                  537   \n",
       "\n",
       "   face_rectangle.width  face_rectangle.height attributes.gender.value  \\\n",
       "0                    90                     90                    Male   \n",
       "1                    65                     65                  Female   \n",
       "2                    54                     54                    Male   \n",
       "3                    53                     53                  Female   \n",
       "4                    52                     52                  Female   \n",
       "5                    48                     48                     NaN   \n",
       "\n",
       "   attributes.age.value  attributes.smile.value  attributes.smile.threshold  \\\n",
       "0                  23.0                  99.995                        50.0   \n",
       "1                  37.0                  98.866                        50.0   \n",
       "2                  23.0                 100.000                        50.0   \n",
       "3                  22.0                  99.997                        50.0   \n",
       "4                  28.0                  99.999                        50.0   \n",
       "5                   NaN                     NaN                         NaN   \n",
       "\n",
       "   attributes.headpose.pitch_angle  ...  \\\n",
       "0                         0.604742  ...   \n",
       "1                         3.239656  ...   \n",
       "2                         5.465557  ...   \n",
       "3                        -2.531932  ...   \n",
       "4                         3.844342  ...   \n",
       "5                              NaN  ...   \n",
       "\n",
       "   attributes.eyegaze.right_eye_gaze.position_x_coordinate  \\\n",
       "0                                              0.457         \n",
       "1                                              0.461         \n",
       "2                                              0.544         \n",
       "3                                              0.302         \n",
       "4                                              0.487         \n",
       "5                                                NaN         \n",
       "\n",
       "   attributes.eyegaze.right_eye_gaze.position_y_coordinate  \\\n",
       "0                                              0.461         \n",
       "1                                              0.437         \n",
       "2                                              0.081         \n",
       "3                                              0.495         \n",
       "4                                              0.402         \n",
       "5                                                NaN         \n",
       "\n",
       "   attributes.eyegaze.right_eye_gaze.vector_x_component  \\\n",
       "0                                             -0.214      \n",
       "1                                             -0.224      \n",
       "2                                             -0.618      \n",
       "3                                             -0.820      \n",
       "4                                             -0.271      \n",
       "5                                                NaN      \n",
       "\n",
       "   attributes.eyegaze.right_eye_gaze.vector_y_component  \\\n",
       "0                                              0.277      \n",
       "1                                              0.158      \n",
       "2                                             -0.531      \n",
       "3                                              0.374      \n",
       "4                                              0.207      \n",
       "5                                                NaN      \n",
       "\n",
       "   attributes.eyegaze.right_eye_gaze.vector_z_component  \\\n",
       "0                                              0.937      \n",
       "1                                              0.962      \n",
       "2                                              0.579      \n",
       "3                                              0.432      \n",
       "4                                              0.940      \n",
       "5                                                NaN      \n",
       "\n",
       "   attributes.skinstatus.health  attributes.skinstatus.stain  \\\n",
       "0                        70.297                        1.686   \n",
       "1                        78.151                        7.777   \n",
       "2                         0.500                        8.234   \n",
       "3                         3.319                        6.990   \n",
       "4                        82.386                        1.748   \n",
       "5                           NaN                          NaN   \n",
       "\n",
       "   attributes.skinstatus.dark_circle  attributes.skinstatus.acne  \\\n",
       "0                              2.601                       0.272   \n",
       "1                              4.751                       6.603   \n",
       "2                              3.244                       0.142   \n",
       "3                              5.649                       0.655   \n",
       "4                              3.866                       0.430   \n",
       "5                                NaN                         NaN   \n",
       "\n",
       "   attributes.glass.value  \n",
       "0                    None  \n",
       "1                    None  \n",
       "2                  Normal  \n",
       "3                  Normal  \n",
       "4                    None  \n",
       "5                     NaN  \n",
       "\n",
       "[6 rows x 61 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_face_rectangle = df[['face_token','face_rectangle.top','face_rectangle.left','face_rectangle.width','face_rectangle.height']]#取出几类想要的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <th>face_rectangle.height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8a6fb634a214e2f309dcb73fde321b9e</td>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1acf34b8b5cf290c9321a73fb01c13a3</td>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9a38db8b08f8677d792c2844a1d7a8d4</td>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4f5d95b66ce2538efa8168b59423cc44</td>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>114c8d0305c8a03d9bd7d29a607601f0</td>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>04c3511fc75d3bd60fd73f67889a33e5</td>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  face_rectangle.top  face_rectangle.left  \\\n",
       "0  8a6fb634a214e2f309dcb73fde321b9e                 123                  138   \n",
       "1  1acf34b8b5cf290c9321a73fb01c13a3                 122                  373   \n",
       "2  9a38db8b08f8677d792c2844a1d7a8d4                  46                  675   \n",
       "3  4f5d95b66ce2538efa8168b59423cc44                  98                  235   \n",
       "4  114c8d0305c8a03d9bd7d29a607601f0                  75                  444   \n",
       "5  04c3511fc75d3bd60fd73f67889a33e5                  98                  537   \n",
       "\n",
       "   face_rectangle.width  face_rectangle.height  \n",
       "0                    90                     90  \n",
       "1                    65                     65  \n",
       "2                    54                     54  \n",
       "3                    53                     53  \n",
       "4                    52                     52  \n",
       "5                    48                     48  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_face_rectangle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle</th>\n",
       "      <th>attributes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8a6fb634a214e2f309dcb73fde321b9e</td>\n",
       "      <td>{'top': 123, 'left': 138, 'width': 90, 'height...</td>\n",
       "      <td>{'gender': {'value': 'Male'}, 'age': {'value':...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1acf34b8b5cf290c9321a73fb01c13a3</td>\n",
       "      <td>{'top': 122, 'left': 373, 'width': 65, 'height...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9a38db8b08f8677d792c2844a1d7a8d4</td>\n",
       "      <td>{'top': 46, 'left': 675, 'width': 54, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Male'}, 'age': {'value':...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4f5d95b66ce2538efa8168b59423cc44</td>\n",
       "      <td>{'top': 98, 'left': 235, 'width': 53, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>114c8d0305c8a03d9bd7d29a607601f0</td>\n",
       "      <td>{'top': 75, 'left': 444, 'width': 52, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>04c3511fc75d3bd60fd73f67889a33e5</td>\n",
       "      <td>{'top': 98, 'left': 537, 'width': 48, 'height'...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  \\\n",
       "0  8a6fb634a214e2f309dcb73fde321b9e   \n",
       "1  1acf34b8b5cf290c9321a73fb01c13a3   \n",
       "2  9a38db8b08f8677d792c2844a1d7a8d4   \n",
       "3  4f5d95b66ce2538efa8168b59423cc44   \n",
       "4  114c8d0305c8a03d9bd7d29a607601f0   \n",
       "5  04c3511fc75d3bd60fd73f67889a33e5   \n",
       "\n",
       "                                      face_rectangle  \\\n",
       "0  {'top': 123, 'left': 138, 'width': 90, 'height...   \n",
       "1  {'top': 122, 'left': 373, 'width': 65, 'height...   \n",
       "2  {'top': 46, 'left': 675, 'width': 54, 'height'...   \n",
       "3  {'top': 98, 'left': 235, 'width': 53, 'height'...   \n",
       "4  {'top': 75, 'left': 444, 'width': 52, 'height'...   \n",
       "5  {'top': 98, 'left': 537, 'width': 48, 'height'...   \n",
       "\n",
       "                                          attributes  \n",
       "0  {'gender': {'value': 'Male'}, 'age': {'value':...  \n",
       "1  {'gender': {'value': 'Female'}, 'age': {'value...  \n",
       "2  {'gender': {'value': 'Male'}, 'age': {'value':...  \n",
       "3  {'gender': {'value': 'Female'}, 'age': {'value...  \n",
       "4  {'gender': {'value': 'Female'}, 'age': {'value...  \n",
       "5                                                NaN  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 立马试试pd.DataFrame 並观察\n",
    "faces_data = results['faces']\n",
    "df = pd.DataFrame(faces_data)\n",
    "df\n",
    "\n",
    "# attributes, face_rectangle, face_token\n",
    "# 查一下API文檔"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    {'top': 123, 'left': 138, 'width': 90, 'height...\n",
       "1    {'top': 122, 'left': 373, 'width': 65, 'height...\n",
       "2    {'top': 46, 'left': 675, 'width': 54, 'height'...\n",
       "3    {'top': 98, 'left': 235, 'width': 53, 'height'...\n",
       "4    {'top': 75, 'left': 444, 'width': 52, 'height'...\n",
       "5    {'top': 98, 'left': 537, 'width': 48, 'height'...\n",
       "Name: face_rectangle, dtype: object"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取变量 (pandas cheetsheet)\n",
    "df[\"face_rectangle\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {'top': 123, 'left': 138, 'width': 90, 'height': 90},\n",
       " 1: {'top': 122, 'left': 373, 'width': 65, 'height': 65},\n",
       " 2: {'top': 46, 'left': 675, 'width': 54, 'height': 54},\n",
       " 3: {'top': 98, 'left': 235, 'width': 53, 'height': 53},\n",
       " 4: {'top': 75, 'left': 444, 'width': 52, 'height': 52},\n",
       " 5: {'top': 98, 'left': 537, 'width': 48, 'height': 48}}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"face_rectangle\"].to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>123</td>\n",
       "      <td>122</td>\n",
       "      <td>46</td>\n",
       "      <td>98</td>\n",
       "      <td>75</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>left</th>\n",
       "      <td>138</td>\n",
       "      <td>373</td>\n",
       "      <td>675</td>\n",
       "      <td>235</td>\n",
       "      <td>444</td>\n",
       "      <td>537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>width</th>\n",
       "      <td>90</td>\n",
       "      <td>65</td>\n",
       "      <td>54</td>\n",
       "      <td>53</td>\n",
       "      <td>52</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>height</th>\n",
       "      <td>90</td>\n",
       "      <td>65</td>\n",
       "      <td>54</td>\n",
       "      <td>53</td>\n",
       "      <td>52</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0    1    2    3    4    5\n",
       "top     123  122   46   98   75   98\n",
       "left    138  373  675  235  444  537\n",
       "width    90   65   54   53   52   48\n",
       "height   90   65   54   53   52   48"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(df[\"face_rectangle\"].to_dict())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>top</th>\n",
       "      <th>left</th>\n",
       "      <th>width</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   top  left  width  height\n",
       "0  123   138     90      90\n",
       "1  122   373     65      65\n",
       "2   46   675     54      54\n",
       "3   98   235     53      53\n",
       "4   75   444     52      52\n",
       "5   98   537     48      48"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(df[\"face_rectangle\"].to_dict()).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_rectangle_top</th>\n",
       "      <th>face_rectangle_left</th>\n",
       "      <th>face_rectangle_width</th>\n",
       "      <th>face_rectangle_height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   face_rectangle_top  face_rectangle_left  face_rectangle_width  \\\n",
       "0                 123                  138                    90   \n",
       "1                 122                  373                    65   \n",
       "2                  46                  675                    54   \n",
       "3                  98                  235                    53   \n",
       "4                  75                  444                    52   \n",
       "5                  98                  537                    48   \n",
       "\n",
       "   face_rectangle_height  \n",
       "0                     90  \n",
       "1                     65  \n",
       "2                     54  \n",
       "3                     53  \n",
       "4                     52  \n",
       "5                     48  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_rect = pd.DataFrame(df[\"face_rectangle\"].to_dict()).T\n",
    "# 欄位名稱加上 face_rectangle \n",
    "df_rect.columns = [ \"face_rectangle_\"+x for x in df_rect.columns]\n",
    "df_rect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle</th>\n",
       "      <th>attributes</th>\n",
       "      <th>face_rectangle_top</th>\n",
       "      <th>face_rectangle_left</th>\n",
       "      <th>face_rectangle_width</th>\n",
       "      <th>face_rectangle_height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8a6fb634a214e2f309dcb73fde321b9e</td>\n",
       "      <td>{'top': 123, 'left': 138, 'width': 90, 'height...</td>\n",
       "      <td>{'gender': {'value': 'Male'}, 'age': {'value':...</td>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1acf34b8b5cf290c9321a73fb01c13a3</td>\n",
       "      <td>{'top': 122, 'left': 373, 'width': 65, 'height...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9a38db8b08f8677d792c2844a1d7a8d4</td>\n",
       "      <td>{'top': 46, 'left': 675, 'width': 54, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Male'}, 'age': {'value':...</td>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4f5d95b66ce2538efa8168b59423cc44</td>\n",
       "      <td>{'top': 98, 'left': 235, 'width': 53, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>114c8d0305c8a03d9bd7d29a607601f0</td>\n",
       "      <td>{'top': 75, 'left': 444, 'width': 52, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>04c3511fc75d3bd60fd73f67889a33e5</td>\n",
       "      <td>{'top': 98, 'left': 537, 'width': 48, 'height'...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  \\\n",
       "0  8a6fb634a214e2f309dcb73fde321b9e   \n",
       "1  1acf34b8b5cf290c9321a73fb01c13a3   \n",
       "2  9a38db8b08f8677d792c2844a1d7a8d4   \n",
       "3  4f5d95b66ce2538efa8168b59423cc44   \n",
       "4  114c8d0305c8a03d9bd7d29a607601f0   \n",
       "5  04c3511fc75d3bd60fd73f67889a33e5   \n",
       "\n",
       "                                      face_rectangle  \\\n",
       "0  {'top': 123, 'left': 138, 'width': 90, 'height...   \n",
       "1  {'top': 122, 'left': 373, 'width': 65, 'height...   \n",
       "2  {'top': 46, 'left': 675, 'width': 54, 'height'...   \n",
       "3  {'top': 98, 'left': 235, 'width': 53, 'height'...   \n",
       "4  {'top': 75, 'left': 444, 'width': 52, 'height'...   \n",
       "5  {'top': 98, 'left': 537, 'width': 48, 'height'...   \n",
       "\n",
       "                                          attributes  face_rectangle_top  \\\n",
       "0  {'gender': {'value': 'Male'}, 'age': {'value':...                 123   \n",
       "1  {'gender': {'value': 'Female'}, 'age': {'value...                 122   \n",
       "2  {'gender': {'value': 'Male'}, 'age': {'value':...                  46   \n",
       "3  {'gender': {'value': 'Female'}, 'age': {'value...                  98   \n",
       "4  {'gender': {'value': 'Female'}, 'age': {'value...                  75   \n",
       "5                                                NaN                  98   \n",
       "\n",
       "   face_rectangle_left  face_rectangle_width  face_rectangle_height  \n",
       "0                  138                    90                     90  \n",
       "1                  373                    65                     65  \n",
       "2                  675                    54                     54  \n",
       "3                  235                    53                     53  \n",
       "4                  444                    52                     52  \n",
       "5                  537                    48                     48  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用.join合併\n",
    "df.join(df_rect)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
